import type { FcPageConfig } from '@/types/fcform'
import { createColums } from './table/columns.ts'
import { createFormItems } from './edit/formItems.ts'
import { createRules } from './edit/rules.ts'
import { createFormItems as createAuthItems } from './auth/formItems.ts'
import { createRules as createAuthRules } from './auth/rules.ts'
export function usePageConfig(): FcPageConfig {
  return {
    KEY: 'roleId',
    pageProps: {
      tools: {
        add: {
          auth: 'sys_role_add',
        },
        del: {
          auth: 'esayIcon-shanchu',
        },
      },
    },
    table: {
      isPaging: false,
      getApi: '/admin/role/list',
      delApi: {
        api: '/admin/role',
        method: 'delete',
        isArray: true,
      },
      createColums,
    },
    edit: {
      default: {
        addApi: '/admin/role',
        editApi: {
          api: '/admin/role',
          method: 'put',
        },
        createItems: createFormItems,
        createRule: createRules,
      },
      auth: {
        title: () => '角色授权',
        addApi: {
          api: '/admin/role/menu',
          method: 'put',
          successText: '授权成功',
        },
        saveParams: (params) => {
          params.menuIds = params.menuIds.toString()
          return params
        },
        createItems: createAuthItems,
        createRule: createAuthRules,
      },
    },
  }
}
